function [accuracy, ylabel, count, tm2]=call_CCCE_eff(piSet, SSet, true_label, alpha, lambda, numiter)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code for C3E
% Inputs:
% piSet:      probability assignments
% SSet:       similarity matrix
% true_label: true labels of the test data
% alpha:      co-efficient of the second term
% lambda:     value of Lagrangian multiplier
% numiter:    maximum number of iterations allowed
% precsn:     minimum precision allowed
% Outputs:    
% accuracy:   accuracy on test data
% ylabel:     class labels of test data as obtained by C3E
% count:      number of iterations performed before percentage difference in objective
% converging to 'precsn'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% if (nargin<7)
%     precsn = 0.000000001;
% end

format long;

ncl = size(piSet,2);    % number of classes
N   = size(piSet,1);    % number of data points

%declaring constants
errctrlr = 0.000000001; % to avoid log(zero)
MAXCOUNT = numiter;

% %lagrangian multipliers for maintaining consistency between right and left copies
% lambdal = lambda*ones(N,1);
% lambdar = lambdal;

%uniform class assignment for unlabeled points
ind=find(diag(piSet*piSet')==0);
if(isempty(ind)==0)
    piSet(ind,:)=1/ncl;
end
piSet=piSet+errctrlr;
piSet=piSet./repmat(sum(piSet,2),1,ncl);

%initialization of class assignment probability vector
yl=ones(N,ncl); %left copy
yl=yl./repmat(sum(yl,2),1,ncl);
yr=yl;          %right copy


% objval=evaluate_obj(piSet, SSet, yl, yr, lambdal, lambdar, alpha);
% iterativeobj(1)=objval;
% convvalue=1000000;


tm1 = cputime;
count=1;

gammar  = repmat((alpha*sum(SSet,1))',1,ncl);
gammal  = repmat(alpha*sum(SSet,2),1,ncl);
delta   = SSet./repmat(sum(SSet,1), N, 1);
% lambdalmat = repmat(lambdal,1,ncl);
% lambdarmat = repmat(lambdar,1,ncl);

while(count<=MAXCOUNT)% && convvalue>precsn)
    
    yr     = (piSet+gammar.*(delta*yl)+lambda*yl)./(1+gammar+lambda);    
    %objvalr= evaluate_obj(piSet, SSet, yl, yr, lambdal, lambdar, alpha);
    
    gradyr = 1+log(yr+errctrlr);
    temp   = (gammal.*(delta*gradyr)+lambda*gradyr)./(gammal+lambda);
    yl     = exp(temp-1);

    %objvall=evaluate_obj(piSet, SSet, yl, yr, lambdal, lambdar, alpha);
    %iterativeobj(count+1)=objvall;
    %convvalue=[iterativeobj(count+1)-iterativeobj(count)]/iterativeobj(count); 
    count=count+1;
end

yl=yl./repmat(sum(yl,2),1,ncl);
yr=yr./repmat(sum(yr,2),1,ncl);
y=[yl+yr]/2;
%finalobjval=evaluate_obj(piSet, SSet, y, y, lambdal, lambdar, alpha);
[ymax ylabel]=max(y');
accuracy=100*length(find(ylabel'==true_label))/N;
%xx=[1:count];
%plot(xx,iterativeobj);
ylabel=ylabel';
% accuracy(count)
% max(accuracy)
%

tm2 = cputime-tm1;
end

